package com.stars.distributed.schedule.client.demo.rocketmq;

import com.jy.modules.rocketmq.producer.RocketMQProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.util.UUID;

/**
 * 回调MQ的demo 回调时作为生产者发送消息，供任务队列进行消费，完成任务的调度
 */
@Configuration
@PropertySource("classpath:rocketMQ.properties")
public class MQDistributedCallBackConfig {
    private static final Logger logger = LoggerFactory.getLogger(MQDistributedCallBackConfig.class);

    @Value("${rocketmq.nameServer}")
    private String nameServer;

    @Value("${com.producer.callback.groupName}")
    private String groupName;

    @Bean(value = "myDistributedMQCallbackInstance", destroyMethod = "shutdown")
    public RocketMQProducer rocketMQProducer() {
        RocketMQProducer rocketMQProducer = new RocketMQProducer(groupName, nameServer, UUID.randomUUID().toString(),4,2,3000);

        logger.info("com-distributed-topic-demo 生产者开始启动, 启动参数[nameServer={}, groupName={}]", nameServer, groupName);
        rocketMQProducer.start();
        logger.info("com-distributed-topic-demo 生产者启动成功");

        return rocketMQProducer;
    }
}